<template>
  <div class="functionType">
    <div class="titleTop first" v-if="pageType !== 'positionDetail'">
      <h3>{{searchType === 'COMPANY'? $t('navigation.position_management'): (searchType === 'PERSONAL' ? $t('navigation.my_position') : $t('navigation.position'))}}</h3>
      <a-button type="primary" v-if="twoArrCludes(['ROLE_HRBP'])"  @click="addPosition">{{$t('position_management.add_position')}}</a-button>
    </div>
    <div :class="pageType !== 'positionDetail' ? 'content' : ''">
      <CountCard v-if="pageType !== 'positionDetail'" :dataList="dataListCardArr"  :status="status" @search="setSearch"/>
      <search-filed  :searchList="[...searchListArr, ...unFieldList]" :selectField="{...formValues, ...unField}" @clear="clearSearch" @close="closeOneField"/>
      <div class="CandidateTable">
        <a-table size="middle" style="padding: 0 12px" :scroll="{ x: true }" :loading="loading" :pagination="pagination" :columns="[...columns, ...columnsStatus]" :dataSource="positionListArr" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" :rowClassName="setRowClassName">
          <template slot="title" >
            <TableOperate ref="TableOperate" :valueFileds="valueFileds"
              :deliveryDate="deliveryDateArr" :searchList="searchListArr" searchTitle="职位名称"
              @chooseDeliveryDate="chooseDeliveryDate" @searchFormValue="searchFormValue"
               :operateBtn="selectedRowKeys.length > 0 && filterBtn(operateBtn).length > 0 ? filterBtn(operateBtn) : null"
                @batchOperation="(id)=>changeStatus(id)"
            ></TableOperate>
          </template>
          <template v-for="item in columns" :slot="item.key" slot-scope="text, record">
            <div :key="item.key">
              <template v-if="item.key === 'name'">
                <div class="updateText"  id="components-badge-demo-dot" :record="record" style="cursor:pointer;display: flex">
                  <!-- <p class="blue_hover" v-if="record.hrSiteType === 'WECHAT'" @click="qrcode('qrcode', record.positionDetailUrl)">{{text}}</p> -->
                  <a-tooltip :overlayStyle="{ maxWidth: '400px' }" v-if="text && text.length > 33">
                    <template slot="title">
                      <span class="blue_hover" style="white-space:wrap">{{text}}</span>
                    </template>
                    <p class="blue_hover" @click="positionPage(record, 'look')">{{text}}</p>
                  </a-tooltip>
                  <span class="blue_hover" v-else @click="positionPage(record, 'look')">{{text}}</span>
                  <!-- <a-badge :count="record.vendorMessCount" :overflow-count="99" :title="`${record.vendorMessCount}条未读消息`" @click="goInfo(record)"> -->
                  <!-- <span>&nbsp;&nbsp;</span>
                  </a-badge> -->
                </div>
                <p class="update ctrlBtn" v-if="record.status === 'PUBLISHING'">
                  <span v-if="twoArrCludes(['ROLE_HRBP'])" @click="positionPage(record, 'edit')">{{$t('common.edit')}}</span>
                  <span href="javascript:;" v-if="twoArrCludes(['ROLE_VENDOR'])" @click="recommedResume(true, record, false)">{{$t('candidateApplication.recommend')}}</span>
                  <!-- <span v-if="searchType === 'COMPANY'" href="javascript:;" @click="distributeResume(true, record)">分配</span> -->
                </p>
                <p v-else>
                  &nbsp;
                </p>
              </template>
              <p v-else-if="item.type === 'SELECT' || item.type === 'RADIO_GROUP'">
                {{text.name}}
              </p>
              <!-- <div v-else-if="item.key === 'job_vendor_array'" style="white-space:normal">
                <a-tag style="margin-bottom: 4px" color="#108ee9" v-for="item in text" :key="item.id" closable @close="(e) => closeVendors(e, record, item.id)">
                  {{item.name}}
                </a-tag>
              </div> -->
              <p v-else-if="item.type === 'LIST'">
                {{record[item.key].map(val => val.name).join('，')}}
              </p>
              <span v-else-if="item.key === 'vendorRecommendCount'" @click="() => $router.push(`/resumes/candidateApplication?positionId=${record.id}`)" :class="'point'">{{ record.vendorRecommendCount }}</span>
              <span v-else-if="item.key === 'datePublished'" @click="filterField(item, record)" :class="item.hasLink ? 'point': ''">{{ record.datePublished | dateYYMMDD }}</span>
              <span v-else-if="item.key === 'startDate'" @click="filterField(item, record)" :class="item.hasLink ? 'point': ''">{{ record.startDate | dateYYMMDD }}</span>
              <!-- <span v-else-if="item.key === 'applyCount'" @click="showResume(record)" style="color:#0166b6;cursor:pointer;">{{ record.applyCount }}</span> -->
              <p v-else-if="item.key === 'detail'" v-html="record.detail" style="max-height:150px;overflow:auto;" @click="filterField(item, record)" :class="item.hasLink ? 'point': ''"></p>
              <span v-else-if="item.key === 'number'" @click="filterField(item, record)" :class="item.hasLink ? 'point': ''">{{ (record.strNumber && record.strNumber !== 'null') ? record.strNumber : record.number }}</span>
              <p v-else @click="filterField(item, record)" :class="item.hasLink ? 'point': ''">{{text}}</p>
            </div>
          </template>
          <template slot="status" slot-scope="text, record">
            <span class="statusBtn" v-html="$t(transition(record))" :style="`background: ${record.status === 'PUBLISHING' ? 'var(--blue-500)' : 'red'}`">
            </span>
          </template>
        </a-table>
      </div>
    </div>
    <a-modal
      title="请扫描二维码"
      :visible="showQrcode"
      :confirm-loading="confirmLoading"
      :footer="null"
      @cancel="showQrcode =false"
      width="300px"
    >
      <div id="qrcode" ref="qrcode" class="qrcode"></div>
    </a-modal>
    <checked-reason :showReason="showReason" @confirm="faildConfirm"/>
    <analysising-modal :fileSize="fileSize" :positionInfo="positionInfo" :searchType="searchType" :callbackId="callbackId" v-if="showAnalysis" />
    <!-- 军工没有编辑简历需要。 猎头编辑简历 -->
    <resume-edit :positionInfo="positionInfo" :visible="isshowResume" :isEdit="true" @close="(type) => recommedResume(false, null, type)" :id="id" :positionId="positionId" :enterpriseId="enterpriseId" :resumeData="null" :resumeId="''"/>
    <!-- <position-rec-resume :positionInfo="positionInfo" v-if="isshowResume" :searchType="searchType" :visible="isshowResume" @close="(data) => recommedResume(false, data)" :positionId="positionId" :sourcePid="sourcePid" :enterpriseId="enterpriseId"/> -->
    <position-distribution :positionInfo="positionInfo" v-if="isdistributeResume" :visible="isdistributeResume" @close="(type) => distributeResume(false, {type})" :positionId="positionId" :sourcePid="sourcePid" :enterpriseId="enterpriseId"/>
  </div>
</template>

<script>
import loGet from 'lodash.get'
import loSet from 'lodash.set'
import CheckedReason from '@/components/position/CheckedReason'
import { mapState, mapMutations } from 'vuex'
import moment from 'moment'
import QRCode from 'qrcodejs2'
import dateFilter from '@/util/date'
import ResumeEdit from '@/components/resume/ResumeEdit'
// import { selectTreeList } from '@/api/employingUnit'
import CountCard from '@/components/CountCard/CountCard'
import PositionDistribution from '@/components/position/PositionDistribution'
import analysisingModal from '@/components/analysisingModal/analysisingModal'
import TableOperate from '@/components/SearchList/TableOperate'
import SearchFiled from '@/components/SearchList/SearchFiled'
import { twoArrCludes, filterBtn, recordBtn } from '@/util/roles'
// import { isPlatform } from '@/util/platform'
import { cancelPosition, positionStatusCount, positionList, positionCategorySelectAll, positionPositionShowConfig, modifyStatus, positionQueryConditions } from '@/api/position'

const operateBtnAll = [{
  name: 'position_management.publish',
  roles: ['ROLE_HRBP'],
  id: 'PUBLISHING'
}, {
  name: 'position_management.revoked',
  roles: ['ROLE_HRBP'],
  id: 'REVOKED'
// }, {
//   name: 'common.delete',
//   roles: ['ROLE_ADMIN'],
//   id: 'delete'
}]
export default {
  name: 'functionType',
  components: { TableOperate, CountCard, SearchFiled, PositionDistribution, analysisingModal, CheckedReason, ResumeEdit },
  props: [ 'pageType' ],
  data () {
    return {
      loGet,
      loSet,
      fileSize: 0,
      showReason: false,
      callbackId: '',
      showAnalysis: false,
      positionInfo: {}, // 操作单列数据临时保存的单条职位数据
      showQrcode: false,
      confirmLoading: false,
      enterpriseId: '',
      unFieldList: [],
      unField: {},
      operateBtnAll,
      operateBtn: [],
      loading: false,
      isshowResume: false,
      isdistributeResume: false,
      status: 'ALL',
      dataListCardArr: [],
      positionListArr: [],
      valueFileds: null,
      searchType: '',
      positionId: '',
      sourcePid: '',
      qr: null,
      columnsStatus: [
        {
          title: this.$t('common.status'),
          dataIndex: 'status',
          key: 'status',
          scopedSlots: { customRender: 'status' }
        }
      ],
      columns: [],
      selectedRowKeys: [],
      selectedRows: [],
      deliveryDateArr: [{
        id: 'all',
        name: 'searchList.dateText'
      }, {
        id: 'triduum',
        name: 'searchList.3D'
      }, {
        id: 'hebdomad',
        name: 'searchList.1W'
      }, {
        id: 'circatrigintan',
        name: 'searchList.1M'
      }, {
        id: 'halfAYear',
        name: 'searchList.6M'
      }],
      searchListArr: [],
      formValues: {},
      pagination: {
        total: 0,
        simple: true,
        current: 1,
        pageSize: 15,
        onChange: this.changePage
      }
    }
  },
  filters: {
    ...dateFilter
  },
  computed: {
    ...mapState({
      userInfo: state => state.user.userInfo,
      showConfig: state => {
        return state.listDisplaySet.showConfig
      }
    }),
    tableScrollX () {
      return [...this.columns, ...this.columnsStatus].length * 200
    }
  },
  watch: {
    showConfig: {
      handler (val, oldVal) {
        this.pagination.pageSize = val.max ? val.max * 1 : 15
        // 判定重复
        if (oldVal.fields && val.fields) {
          this.modifyShowConfig()
        }
      }
    },
    $route: {
      handler (val, oldVal) {
        if (!oldVal || val.query.status !== oldVal.query.status) {
          this.status = val.query.status || 'ALL'
          this.pagination.current = 1
          this.getPosition()
        }
      },
      immediate: true
    }
  },
  created () {
    let path = this.$route.path
    this.searchType = path === '/company/positionManagement' ? 'COMPANY' : (path === '/myPosition' ? 'PERSONAL' : '') // 判定目录
    this.getPositionQueryConditions()
    if (this.$route.query.status) { // 状态跳转
      this.status = this.$route.query.status
    }
    if (this.$route.query.categoryId) { // 职位界面跳转过来
      this.valueFileds = {
        category: this.$route.query.categoryId
      }
    }
    this.statusCount() // 获取卡片数据下拉数据
    this.setshowConfig() // 获取展示字段
    VBUS.$on('deleteSuccess', (params) => {
      if (params) {
        setTimeout(() => {
          this.getPosition()
        }, 500)
      }
    })
    VBUS.$on(pararm => {
      console.log(pararm)
    })
  },
  methods: {
    ...mapMutations('listDisplaySet', ['SET_FIELD']),
    // isPlatform,
    twoArrCludes,
    moment,
    filterBtn,
    recordBtn,
    async closeVendors (e, record, vendorId) { // 猎头公司职位，删除分配给职位的猎头账号
      e.preventDefault()
      let params = {
        positionId: record.id,
        vendorIds: vendorId
      }
      let res = await cancelPosition(params)
      if (res.code === 200) {
        record.job_vendor_array = record.job_vendor_array.filter(item => item.id !== vendorId)
        this.$message.success(res.message)
      } else {
        this.$message.error(res.message)
      }
    },
    qrcode (id, url) {
      if (this.qr) {
        this.$refs.qrcode.innerHTML = ''
        this.qr.clear()
      }
      this.showQrcode = true
      this.confirmLoading = true
      this.$nextTick(() => {
        this.qr = new QRCode(id, {
          width: 200, // 二维码宽度，单位像素
          height: 200, // 二维码高度，单位像素
          text: url // 生成二维码的链接
        })
        this.confirmLoading = false
      })
    },
    goInfo (item) {
      this.$router.push(`/position/positionEditing?positionId=${item.id}&searchType=${this.searchType}&enterpriseId=${item.enterpriseId}&sourcePid=${item.sourcePid}&activeKey=3`)
    },
    transition (val) {
      if (val.status === 'PUBLISHING') {
        return 'position_management.topublishing'
      } else {
        return 'position_management.revokeding'
      }
    },
    faildConfirm ({ flag, reasonContent }) {
      if (flag) {
        this.sendAuditPosition('FAILAUDIT', reasonContent)
      } else {
        this.showReason = false
      }
    },
    distributeResume (flag, record) {
      if (record.type) {
        this.getPosition()
      }
      this.positionInfo = flag ? record : {}
      this.isdistributeResume = flag
    },
    recommedResume (flag, record, type) {
      if (type) {
        this.statusCount() // 获取卡片数据下拉数据
        this.getPosition()
      }
      if (record) {
        this.positionId = record ? record.id : ''
        this.positionInfo = flag ? record : {}
      }
      this.isshowResume = flag
    },
    async getPositionQueryConditions  () {
      let params = {
        searchType: this.searchType
      }
      let res = await positionQueryConditions(params)
      if (res.code === 200) {
        this.searchListArr = res.data
        // this.getTreelist()
      } else {
        this.$message.error(res.message)
      }
    },
    // async getTreelist () {
    //   this.searchListArr.some((element, index) => {
    //     if (element.id === 'enterpriseId') {
    //       let arr = resizeTree(element.treeData, 'id')
    //       this.$set(this.searchListArr[index], 'treeData', arr)
    //       return true
    //     }
    //   })
    //   if (this.$route.query.enterpriseId) { // 职位界面跳转过来
    //     this.valueFileds = {
    //       enterpriseId: this.$route.query.enterpriseId
    //     }
    //   }
    // },
    filterField (item, record) {
      if (!item.hasLink) return
      this.pagination.current = 1
      if (item.originalKey === 'enterpriseId' || item.originalKey === 'jobType' || item.originalKey === 'category') {
        this.valueFileds = {}
        this.$set(this.valueFileds, item.originalKey, this.loGet(record, item.originalKey))
      } else if (item.originalKey === 'endDate') {
        this.valueFileds = {}
        this.$set(this.valueFileds, item.originalKey, moment(this.loGet(record, item.originalKey), 'YYYY-MM-DD'))
      } else if (item.originalKey === 'datePublished') {
        this.valueFileds = {}
        this.$set(this.valueFileds, item.originalKey, [moment(this.loGet(record, item.originalKey), 'YYYY-MM-DD'), moment(this.loGet(record, item.originalKey), 'YYYY-MM-DD')])
      } else {
        this.$set(this.unField, item.key, this.loGet(record, item.key))
        this.getPosition()
      }
    },
    closeOneField (id) {
      this.valueFileds = {}
      if (id === 'datePublished') {
        this.$refs.TableOperate.clearDate()
      }
      if (this.unField[id]) {
        this.$set(this.unField, id, '')
        this.getPosition()
      } else {
        this.valueFileds = {}
        this.$set(this.valueFileds, id, '')
      }
    },
    changeStatus (status) {
      let positionList = this.selectedRows.map(item => {
        return item.id
      })
      this.tmpList = positionList
      this.sendModifyStatus(status)
    },
    async sendModifyStatus (status) {
      let params = this.tmpList.map(item => {
        return { id: item, status }
      })
      let res = await modifyStatus(params)
      if (res.code === 200) {
        this.statusCount()
        this.getPosition()
        this.$message.success(res.message)
      } else {
        this.$message.error(res.message)
      }
    },
    // async sendAuditPosition (status, auditFailReason) {
    //   let params = {
    //     auditFailReason,
    //     status,
    //     positionList: this.tmpList
    //   }
    //   let res = await auditPosition(params)
    //   if (res.code === 200) {
    //     this.showReason = false
    //     this.$message.success(res.message)
    //     this.getPosition()
    //   } else {
    //     this.$message.error(res.message)
    //   }
    // },
    showResume (record) {
      this.$router.push(`/resume/candidateApplication?positionId=${record.id}`)
    },
    //     const operateBtnAll = [{
    //   name: 'position_management.publish',
    //   roles: ['NORMAL', 'COMPANY_MANAGER'],
    //   id: 'PUBLISHING'
    // }, {
    //   name: 'position_management.revoked',
    //   // roles: ['NORMAL', 'COMPANY_MANAGER'],
    //   id: 'REVOKED'
    // }, {
    //   name: 'position_management.pause',
    //   roles: ['NORMAL', 'COMPANY_MANAGER'],
    //   id: 'PAUSE'
    // }, {
    //   name: 'position_management.publishing',
    //   roles: ['SITE_MANAGER'],
    //   id: 'PUBLISHING1'
    // }, {
    //   name: 'position_management.failaudit',
    //   roles: ['SITE_MANAGER'],
    //   id: 'FAILAUDIT'
    // }, {
    //   name: 'common.delete',
    //   roles: ['NORMAL', 'COMPANY_MANAGER'],
    //   id: 'DROP'
    // }]
    //     FAILAUDIT
    // PUBLISHING
    // PAUSE
    // REVOKED
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
      if (this.selectedRows.every(item => item.drop) && (twoArrCludes(['COMPANY_MANAGER']) || (this.userInfo.permissions && this.userInfo.permissions.includes('editPosition')))) {
        this.operateBtn = [{
          name: 'common.reset',
          roles: ['NORMAL', 'COMPANY_MANAGER'],
          id: 'RECOVER'
        }]
      } else {
        this.operateBtn = this.operateBtnAll.filter(item => {
          if (item.id === 'PUBLISHING') { // 发布
            return this.selectedRows.every(item => item.status !== 'PUBLISHING')
          } else if (item.id === 'REVOKED') { // 下线
            return this.selectedRows.every(item => item.status === 'PUBLISHING')
          } else {
            return true
          }
        })
      }
    },
    setSearch (item) {
      // this.status = item.code
      // this.isActivation = item.id
      this.$router.push({ query: { status: item.key } })
      // this.getPosition(this.formValues)
    },
    async modifyShowConfig () {
      this.loading = true
      localStorage.setItem('positionShowConfig' + this.userInfo.id, JSON.stringify(this.showConfig)) // 更新缓存数据
      let fields = this.showConfig.fields
      // fields.forEach(ele => {
      //   // ele['originalKey'] = ele.key
      //   if ((ele.type === 'RADIO_GROUP' || ele.type === 'SELECT') && ele.key !== 'jobCategory' && ele.key.indexOf('str') === -1 && ele.key !== 'enterpriseId') {
      //     // ele.key = ele.key.charAt(0).toUpperCase() + ele.key.slice(1)
      //     ele.key = 'str' + ele.key.charAt(0).toUpperCase() + ele.key.slice(1)
      //   }
      //   if (ele.type === 'LOCATION') {
      //     ele.key = 'baseProvinceCity'
      //   }
      //   if (ele.key === 'enterpriseId' || ele.key === 'strEnterpriseName') {
      //     ele.key = 'enterpriseName'
      //   }
      //   if (ele.key === 'job') {
      //     ele.key = 'job.name'
      //   }
      // })
      // let obj = {
      //   fields,
      //   searchFields: this.showConfig.searchFields,
      //   max: this.showConfig.max,
      //   searchType: this.searchType
      // }
      // if (!this.showConfig.max) return false
      // let res = await positionAddOrModifyShowConfig(obj)
      // if (res.code === 200) {
      this.unFieldList = []
      let tmp = fields.filter(item => item.checked)
      this.columns = tmp.map(item => {
        this.unFieldList.push({ id: item.key, name: item.value })
        return { title: item.value, dataIndex: item.key, key: item.key, scopedSlots: { customRender: item.key }, hasLink: item.hasLink, originalKey: item.originalKey, type: item.type }
      })
      this.getPosition()
    // }
    },
    async statusCount () {
      let params = {
        searchType: this.searchType
      }
      let res = await positionStatusCount(params)
      if (res.code === 200) {
        this.dataListCardArr = res.data
      }
    },
    async category () {
      let res = await positionCategorySelectAll() // 获取职业类别树状结构接口(闫永清)
      if (res.code === 200) {
        let arr = []
        arr = resizeTree(res.data)
        this.searchListArr.forEach((element, index) => {
          if (element.id === 'category') {
            // element.treeData = arr
            this.$set(this.searchListArr[index], 'treeData', arr)
          }
        })
      }
    },
    setshowConfigData (data) {
      this.columns = []
      this.unFieldList = []
      data.fields.forEach(item => {
        if (item.key !== 'status' && item.checked) {
          this.columns.push({ title: item.value, dataIndex: item.key, key: item.key, scopedSlots: { customRender: item.key }, hasLink: item.hasLink, originalKey: item.originalKey, type: item.type })
          this.unFieldList.push({ id: item.key, name: item.value })
        }
      })
      this.pagination.pageSize = data.max
      this.SET_FIELD(data)
    },
    async setshowConfig () {
      let candidateShowConfig = localStorage.getItem('positionShowConfig' + this.userInfo.id) // 获取缓存数据，有的话不进行请求
      if (candidateShowConfig) {
        this.$nextTick(() => {
          this.setshowConfigData(JSON.parse(candidateShowConfig))
        })
        return
      }
      let res = await positionPositionShowConfig()
      if (res.code === 200) {
        if (res.data && res.data.fields) {
          this.setshowConfigData(res.data)
        }
      }
      if (!this.$route.query.enterpriseId && !this.$route.query.categoryId) {
        this.getPosition()
      }
    },
    async getPosition (values) {
      this.loading = true
      this.selectedRowKeys = []
      let obj = {
        offset: (this.pagination.current - 1) * this.pagination.pageSize,
        max: this.pagination.pageSize,
        queryFilter: {
          status: this.status === 'ALL' ? '' : this.status,
          positionName: this.formValues.keyword,
          ...this.formValues,
          ...this.unField
        } }
      let res = await positionList(obj)
      if (res.code === 200) {
        this.positionListArr = res.data.items
        this.pagination.total = res.data.totalCount
      }
      this.loading = false
    },
    setRowClassName (record, index) {
      return index % 2 === 0 ? 'grey' : ''
    },
    clearSearch () {
      this.unField = {}
      this.$refs.TableOperate.clearDate()
      this.$refs.TableOperate.clearSearch()
    },
    chooseDeliveryDate (item) { // 职位发布日期搜索
      let values = {}
      if (item.id === 'triduum') {
        values.datePublished = {
          from: moment().subtract('days', 3).format('YYYY-MM-DD'),
          to: moment().format('YYYY-MM-DD')
        }
      } else if (item.id === 'hebdomad') {
        values.datePublished = {
          from: moment().subtract('days', 7).format('YYYY-MM-DD'),
          to: moment().format('YYYY-MM-DD')
        }
      } else if (item.id === 'circatrigintan') {
        values.datePublished = {
          from: moment().subtract('days', 30).format('YYYY-MM-DD'),
          to: moment().format('YYYY-MM-DD')
        }
      } else if (item.id === 'halfAYear') {
        values.datePublished = {
          from: moment().subtract('days', 183).format('YYYY-MM-DD'),
          to: moment().format('YYYY-MM-DD')
        }
      } else if (item.id === 'all') {
        values.datePublished = {}
      } else {
        values.datePublished = {}
      }
      this.pagination.current = 1
      // 赋值
      this.valueFileds = {
        datePublished: values.datePublished.from ? [moment(values.datePublished.from, 'YYYY-MM-DD'), moment(values.datePublished.to, 'YYYY-MM-DD')] : ''
      }
    },
    searchFormValue (values) { // 条件搜索
      if (values.datePublished) {
        values.datePublished = {
          from: moment(values.datePublished[0]).format('YYYY-MM-DD'),
          to: moment(values.datePublished[1]).format('YYYY-MM-DD')
        }
      }
      if (values.endDate) {
        values.endDate = {
          from: moment(values.endDate).format('YYYY-MM-DD'),
          to: moment(values.endDate).format('YYYY-MM-DD')
        }
      }
      if (this.formValues.datePublished && values.datePublished && values.datePublished.to !== this.formValues.datePublished.to && values.datePublished.from !== this.formValues.datePublished.from) {
        this.$refs.TableOperate.clearDate()
      }
      this.formValues = values
      this.pagination.current = 1
      this.getPosition()
    },
    // 分页
    changePage (current, pageSize) {
      this.pagination.current = current
      this.pagination.pageSize = pageSize
      this.getPosition()
    },
    positionPage (item, val) {
      let list = []
      list = this.positionListArr.map((item, index) => {
        return { id: item.id, recruitmentTypeId: item.weChatPositionType.id }
      })
      let obj = { list, backPath: this.$route.fullPath }
      sessionStorage.setItem('positionList', JSON.stringify(obj))
      if (val === 'edit') {
        // if (this.searchType) {
        //   this.$router.push(`/position/positionEditing?positionId=${item.id}&searchType=${this.searchType}&enterpriseId=${item.enterpriseId}&sourcePid=${item.sourcePid}`)
        // } else {
        this.$router.push(`/position/positionEditing?pid=${item.id}&recruitmentTypeId=${item.weChatPositionType.id}`)
        // }
      } else if (val === 'look') {
        this.$router.push(`/position/positionDetail?positionId=${item.id}&recruitmentTypeId=${item.weChatPositionType.id}`)
      }
    },
    async deleteAcct (record) {
      let params = {
        status: 'DROP',
        positionList: [{ enterpriseId: record.enterpriseId, positionId: record.id }]
      }
      let res = await modifyStatus(params)
      if (res.code === 200) {
        this.getPosition()
        this.$message.success(res.message)
      } else {
        this.$message.error(res.message)
      }
    },
    addPosition () {
      this.$router.push(`/position/positionEditing?type=addPosition`)
    }
  },
  beforeDestroy () {
    this.SET_FIELD({})
  }
}
function resizeTree (arr, field = 'id', key = 0) {
  if (!Array.isArray(arr)) return
  return arr.map((item, index) => {
    let treekey = `${key}-${index}`
    return { title: item.name, value: item[field], id: item[field], children: resizeTree(item.children, field, treekey) }
  })
}
</script>

<style lang="stylus" scoped>
@import '../../styles/var.styl'
.qrcode
  display flex
  justify-content center
  align-items center
.functionType
  width  100%
  .titleTop
    background #fff
    display flex
    align-items center
    justify-content flex-start
    padding  0 24px 12px
    h3
      margin-right 24px
      font-size 18px
      font-weight bold
    button
      margin-left 12px
  .content
    padding 12px 24px
  .CandidateTable
    background #fff
    :global(.ant-table-title)
      padding 0
    :global(.ant-table-thead th)
      white-space nowrap
      background none
      padding 0
    :global(.ant-table-thead .ant-table-header-column)
      display inline-block
      width calc(100% - 16px)
      padding 5px 8px
      margin 5px 8px
      border-right 1px solid borderColor
    :global(.ant-table-thead th:first-child .ant-table-header-column)
    :global(.ant-table-thead th:last-child .ant-table-header-column)
      border-right none
    :global(.ant-table-tbody >tr >td)
      white-space nowrap
      padding 7px 16px
      vertical-align top
      div
        >p
          white-space normal
          width 190px
          max-width 256px
          overflow : hidden;
          text-overflow: ellipsis;
          display -webkit-box
          -webkit-line-clamp 3 // 规定几行显示省略号
          -webkit-box-orient vertical
    :global(.grey)
      background var(--light-grey)
    .updateText
      font-weight 600
      margin 0
    .update
      // visibility hidden
      margin 6px 0 0
      span
        display none
        cursor pointer
        // border-right 1px solid borderColor
        padding 0
        color var(--blue-500)
        &:first-child
          padding-left 0
        &:last-child
          color errorColor
          &:after
            height 0
        &:after
          content ''
          vertical-align middle
          background borderColor
          display inline-block
          height 14px
          width 1px
          margin-left 4px
      &.ctrlBtn
        span
          color var(--blue-500)!important
    .statusBtn
      display inline-block
      // width 60px
      border-radius: 15px;
      padding: 2px 8px;
      height: 24px;
      color #fff
      text-align center
      line-height 20px
    :global(.ant-table-row)
      margin 0 12px
    :global(.ant-table-row:hover)
      .blue_hover
        color var(--blue-500)
      .update
        >span
          // visibility visible
          display inline-block
    .pagination_wrapper
      padding 5px 0
      text-align right
  :global(.CandidateTable)
    margin-top 12px
  :global(.SearchFiled)
    margin-top 12px
.point
  cursor pointer
  &:hover
    color var(--blue-500)
</style>
<style lang="stylus">
:global(.ant-scroll-number-only > p.ant-scroll-number-only-unit)
  color #fff
</style>
